import request from "@/utils/request";
// import axios from 'axios'
import { apiVersion } from "@/config";

// 创建 collection
export function addCollection(name) {
	return request({
		url: `/admin/${apiVersion}/metric/collection`,
		method: "post",
		data: { name },
	});
}

// 获取 collection 列表
export function getCollection() {
	return request({
		url: `/admin/${apiVersion}/metric/collection`,
		method: "get",
	});
}

// 按照项目获取 collection 列表
export function getCollectionByProject(projectId) {
	return request({
		url: `/admin/${apiVersion}/metric/collectionByProject/${projectId}`,
		method: "get",
	});
}

// 获取 document 列表
export function getDocument({ collection, pageNum, pageSize }) {
	return request({
		url: `/admin/${apiVersion}/metric/document`,
		method: "get",
		data: {
			collection,
			pageNum,
			pageSize,
		},
	});
}

// 创建 document
export function addDocument({ collection, document }) {
	return request({
		url: `/admin/${apiVersion}/metric/document`,
		method: "post",
		data: {
			collection,
			document,
		},
	});
}

// 修改 document
export function updateDocument({ collection, document }) {
	return request({
		url: `/admin/${apiVersion}/metric/document`,
		method: "put",
		data: {
			collection,
			document,
		},
	});
}

// 删除 document
export function delDocument({ collectionName, id }) {
	return request({
		url: `/admin/${apiVersion}/metric/document/${collectionName}/${id}`,
		method: "delete",
	});
}

// 一键去重 document
export function removeWeightDocument({ collection, project_id }) {
	return request({
		url: `/admin/${apiVersion}/metric/document/dedup`,
		method: "put",
		data: {
			collection,
			project_id,
		},
	});
}

// 一键删除 document
export function removeAllDocument({ collectionName, projectId }) {
	return request({
		url: `/admin/${apiVersion}/metric/deleteDocumentByProject/${collectionName}/${projectId}`,
		method: "delete",
		data: {},
	});
}
